package com.twj.tools.poi;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.twj.tools.parse.CastUtils;
import com.twj.tools.parse.JsonUtils;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * https://blog.csdn.net/weixin_47384874/article/details/122713563?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-122713563-blog-97231176.235%5Ev38%5Epc_relevant_anti_vip_base&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-122713563-blog-97231176.235%5Ev38%5Epc_relevant_anti_vip_base&utm_relevant_index=2
 * <p>
 * https://blog.csdn.net/weixin_43549578/article/details/128039264
 *
 * @author 作者: tianwenju
 * @version 1.0
 * @project 金税三期工程核心征管及应用总集成项目
 * @package com.css.dsjypt
 * @file WordPdfTest.java 创建时间:2023年06月26日 16:46
 * @title 标题（要求能简洁地表达出类的功能和职责）
 * @description 描述（简要描述类的职责、实现方式、使用注意事项等）
 * @copyright Copyright (c) 2020 中国软件与技术服务股份有限公司
 * @company 中国软件与技术服务股份有限公司
 * @module 模块: 模块名称
 * @reviewer 审核人:
 * @history 修订历史（历次修订内容、修订人、修订时间等）
 */
public class PdfTest {
    public static void main(String[] args) throws IOException {
        String filename = "D:\\test\\1table.pdf";
//        String table = "D:\\test\\table.pdf";
//        createPDF(table);
        createPDF3(filename);
        System.out.println("打印完成");
    }

    //定义全局的字体静态变量
    private static Font titlefont;
    private static Font headfont;
    private static Font headbody;
    private static Font keyfont;
    private static Font textfont;
    private static Font imageFont;
    // 最大宽度
    private static int maxWidth = 360;

    /**
     * 居左
     */
    private final static int ALIGN_LEFT = 0;
    /**
     * 居中
     */
    private final static int ALIGN_CENTER = 1;
    /**
     * 居右
     */
    private final static int ALIGN_RIGHT = 2;

    // 静态代码块
    static {
        try {
            // 不同字体（这里定义为同一种字体：包含不同字号、不同style）   只需要将itextpdf版本改为5.5.5; itext-asian版本改为5.2.0即可
//            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

//            Font font = new Font(BaseFont.createFont("D:/test/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED));
            BaseFont bfChinese = BaseFont.createFont("D:/test/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            //引入特殊字符的字体
            BaseFont baseFont = BaseFont.createFont("D:\\test\\ttc\\msgothic.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            imageFont = new Font(baseFont);
            titlefont = new Font(bfChinese, 14, Font.BOLD);
            headfont = new Font(bfChinese, 12, Font.BOLD);
            headbody = new Font(bfChinese, 12, Font.NORMAL);
            keyfont = new Font(bfChinese, 10, Font.BOLD);
            textfont = new Font(bfChinese, 10, Font.NORMAL);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createPDF(String filename) throws IOException {
        Document document = new Document(PageSize.A4);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            document.addTitle("example of PDF");
            document.open();
            // 段落
            Paragraph paragraph = new Paragraph("pdf表格模板", titlefont);
            paragraph.setAlignment(1); //设置文字居中 0靠左   1，居中     2，靠右
            paragraph.setIndentationLeft(12); //设置左缩进
            paragraph.setIndentationRight(12); //设置右缩进
            paragraph.setFirstLineIndent(24); //设置首行缩进
            //paragraph.setLeading(50f); //行间距
            paragraph.setSpacingBefore(5f); //设置段落上空白
            paragraph.setSpacingAfter(10f); //设置段落下空白
            document.add(paragraph);

            Chunk chunk1 = new Chunk("是");
            chunk1.setFont(headbody);
            Chunk chunk2 = new Chunk("☑");
            chunk2.setFont(imageFont);

            //增加块到文档
          /*  document.add(chunk1);
            document.add(chunk2);*/
            //短语
            Phrase phrase = new Phrase();
            phrase.add(chunk1);
            phrase.add(chunk2);
            Paragraph paragraph2 = new Paragraph(phrase);
            document.add(paragraph2);

            PdfPTable table = createTable(writer);


            //设置table的宽度并且锁定
            table.setTotalWidth(PageSize.A4.getWidth() - 100);
            table.setLockedWidth(true);
            document.add(table);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
            document.close();
        }
    }

    public static void createPDF3(String filename) throws IOException {
        Document doc = new Document(PageSize.A4);
        try {
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
            doc.addTitle("example of PDF");
            doc.open();


            createTitle(doc, "个人基本情况", ALIGN_CENTER);
            createGrjbqkTable(doc);
            createTitle(doc, "个人履历情况", ALIGN_CENTER);
            createGrllTable(doc);
            createTitle(doc, "履职记录情况", ALIGN_CENTER);
            createLzjlTable(doc);
            createTitle(doc, "重点工作情况", ALIGN_CENTER);
            createZdgzTable(doc);

            createTitle(doc, "学历学位情况", ALIGN_CENTER);
            createXlxwTable(doc);
            createTitle(doc, "年度考核情况", ALIGN_CENTER);
            createNdkhTable(doc);

            createTitle(doc, "奖励惩戒情况", ALIGN_CENTER);
            createJlcjTable(doc);

            createTitle(doc, "人才及两测情况", ALIGN_CENTER);
            createRcjlcTable(doc);

            createTitle(doc, "性格行为情况", ALIGN_CENTER);
            createXgxwTable(doc);

            createTitle(doc, "家庭成员情况", ALIGN_CENTER);
            createJtcyTable(doc);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
            doc.close();
        }
    }


    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @description title类型字体段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    public static void createTitle(Document document, String text, int align) throws DocumentException {
        createParagraph(document, text, align, titlefont);
    }

    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @description head类型字体段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    private static void createHead(Document document, String text, int align) throws DocumentException {
        createParagraph(document, text, align, headfont);
    }

    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @description key类型字体段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    private static void createKey(Document document, String text, int align) throws DocumentException {
        createParagraph(document, text, align, keyfont);
    }

    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @description text类型字体段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    private static void createText(Document document, String text, int align) throws DocumentException {
        createParagraph(document, text, align, textfont);
    }

    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @description head类型字体 段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    public static void createHeadBody(Document document, String text, int align) throws DocumentException {
        createParagraph(document, text, align, headbody);
    }

    /**
     * @param document 文档
     * @param text     文本
     * @param align    对齐方式
     * @Font font    字体
     * @description 创建段落
     * @time 创建时间：2023/7/11 15:18
     * @author 作者：tianwenju
     * @history 修订历史（历次修订内容、修订人、修订时间等）
     */
    public static void createParagraph(Document document, String text, int align, Font font) throws DocumentException {
        // 段落
        Paragraph paragraph = new Paragraph(text, font);
        paragraph.setAlignment(align); //设置文字居中 0靠左   1，居中     2，靠右
        paragraph.setIndentationLeft(12); //设置左缩进
        paragraph.setIndentationRight(12); //设置右缩进
        paragraph.setFirstLineIndent(24); //设置首行缩进
        //paragraph.setLeading(50f); //行间距
        paragraph.setSpacingBefore(5f); //设置段落上空白
        paragraph.setSpacingAfter(10f); //设置段落下空白
        document.add(paragraph);
    }

    public static void createPDF2(String filename) throws IOException {
        Map<String, Object> param = new HashMap<String, Object>();

        param.put("${topic}", "主题一：二八定律");
        param.put("${subhead}", "从税收数据分布，“抓住”其关键少数");
        param.put("${txt1}", "著名的经济学家帕累托提出的“二八定律”指出80%的财富是由20%的人创造的。在中国，19个城市群承载了全国3/4以上人口，贡献了八成以上GDP；与之类似，全球共223个国家与地区，其中20国集团GDP总量占全球85%，贸易占全球贸易总额的80%以上，人口占全球人口的2/3。“关键少数”对指导开展管理活动非常有帮助。");
        param.put("${txt2}", "基于“五个一”归集数据，我们发现对于国家税收来说，同样也有许多情况符合二八定理。比如，大量的税收收入来自于数量较少的大企业、大量的个税收入也是来源于少数的高收入人群等。");
        param.put("${xx1}", "现象一：【X%】的【维度/标签】贡献了【Y%】的【指标】");
        param.put("${xx1txt0}", "全国【YYYY】年【X%】【维度/标签】贡献了【Y%】【指标】，主要集中在【省份】、【行业】，呈现了一定的聚集性。");
        param.put("${xx1txt1}", "1.【YYYY】年，全国【指标】合计值为【XXX】【单位】，其中【X%】的【维度/标签】贡献了【指标】合计值为【XXX】【单位】，占全国【指标】合计值【百分比%】，【指标】贡献排名前三的省份分别为【XX省】、【XX省】和【XX省】，分别占全国总量的【百分比%】、【百分比%】和【百分比%】，（详见表X.1）。");
        param.put("${xx1txt2}", "2. 【YYYY】年，全国【指标】行业集中情况，【指标】排名前三的行业分别为【XX行业】、【XX行业】和【XX行业】，分别占全国总量的【百分比%】、【百分比%】和【百分比%】，（详见表X.2）。");

        Document document = new Document(PageSize.A4);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            document.addTitle("主题一：二八定律hhd");
            document.open();
            createParagraph(document, "主题一：二八定律", 1);
            createParagraph(document, "著名的经济学家帕累托提出的“二八定律”指出80%的财富是由20%的人创造的。在中国，19个城市群承载了全国3/4以上人口，贡献了八成以上GDP；与之类似，全球共223个国家与地区，其中20国集团GDP总量占全球85%，贸易占全球贸易总额的80%以上，人口占全球人口的2/3。“关键少数”对指导开展管理活动非常有帮助。", 0);
            createParagraph(document, "基于“五个一”归集数据，我们发现对于国家税收来说，同样也有许多情况符合二八定理。比如，大量的税收收入来自于数量较少的大企业、大量的个税收入也是来源于少数的高收入人群等。", 0);
            createParagraph(document, "现象一：【X%】的【维度/标签】贡献了【Y%】的【指标】", 0);
            createParagraph(document, "附件：", 0);

           /* Chunk chunk1 = new Chunk("是");
            chunk1.setFont(headbody);
            Chunk chunk2 = new Chunk("☑");
            chunk2.setFont(imageFont);

            //增加块到文档
          *//*  document.add(chunk1);
            document.add(chunk2);*//*
            //短语
            Phrase phrase = new Phrase();
            phrase.add(chunk1);
            phrase.add(chunk2);
            Paragraph paragraph2 = new Paragraph(phrase);
            document.add(paragraph2);*/


            PdfPTable table = createTable2(writer);
            //设置table的宽度并且锁定
            table.setTotalWidth(PageSize.A4.getWidth() - 100);
            table.setLockedWidth(true);
            document.add(table);
            createParagraph(document, "附件2：", 0);
            PdfPTable table2 = createTable2(writer);
            //设置table的宽度并且锁定
            table2.setTotalWidth(PageSize.A4.getWidth() - 100);
            table2.setLockedWidth(true);
            document.add(table2);

            createParagraph(document, "图片示例：", 0);
            Image image = Image.getInstance("D:\\test\\pic\\img3.png");
            image.setAlignment(Image.ALIGN_CENTER);
            image.scalePercent(80); //依照比例缩放
//            image.setAbsolutePosition(20,60);
            document.add(image);
            createParagraph(document, "图片示例2：", 0);

            Image image2 = Image.getInstance("D:\\test\\pic\\img5.png");
            image2.setAlignment(Image.ALIGN_CENTER);
            image2.scalePercent(80); //依照比例缩放
//            image2.setAbsolutePosition(20,20);
            document.add(image2);
            createParagraph(document, "不错 不错", 0);
            Image image3 = Image.getInstance("D:\\test\\pic\\img5.png");
            image3.setAlignment(Image.ALIGN_CENTER);
            image3.scalePercent(40); //依照比例缩放
//            image2.setAbsolutePosition(20,20);
            document.add(image3);
            createParagraph(document, "棒 不错", 0);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
            document.close();
        }
    }

    private static void createParagraph(Document document, String text, int align) throws DocumentException {
        // 段落
        Paragraph paragraph = new Paragraph(text, titlefont);
        paragraph.setAlignment(align); //设置文字居中 0靠左   1，居中     2，靠右
        paragraph.setIndentationLeft(12); //设置左缩进
        paragraph.setIndentationRight(12); //设置右缩进
        paragraph.setFirstLineIndent(24); //设置首行缩进
        //paragraph.setLeading(50f); //行间距
        paragraph.setSpacingBefore(5f); //设置段落上空白
        paragraph.setSpacingAfter(10f); //设置段落下空白
        document.add(paragraph);
    }


    //生成一个两列的表格
    public static PdfPTable createTable(PdfWriter writer) throws DocumentException, IOException {
        // 添加图片
//        Image image = Image.getInstance("https://img2.baidu.com/it/u=1603121828,1164719810&fm=253&fmt=auto&app=138&f=JPEG?w=769&h=500");
        Image image = Image.getInstance("D:\\test\\pic\\b2.jpg");
        image.setAlignment(Image.ALIGN_CENTER);
        image.scalePercent(40); //依照比例缩放
        image.setAbsolutePosition(40, 60);

        PdfPTable table = new PdfPTable(9);

        table.addCell(createCell("个人信息", textfont, 1, 1, 3));
        table.addCell(createCell("名称", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));
        table.addCell(createCell("照片", textfont, 1, 2, 3));

        table.addCell(createCell(image, textfont, 1, 2, 3));

        table.addCell(createCell("地址", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));

        table.addCell(createCell("电话", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));


        table.addCell(createCell("其他信息", textfont, 1, 1, 3));
        table.addCell(createCell("名称", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));
        table.addCell(createCell("身份证号", textfont, 1, 2, 1));
        table.addCell(createCell("", textfont, 1, 2, 1));
        table.addCell(createCell("地址", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));
        table.addCell(createCell("开户银行", textfont, 1, 2, 1));
        table.addCell(createCell("", textfont, 1, 2, 1));
        table.addCell(createCell("电话", textfont, 1, 1));
        table.addCell(createCell("", textfont, 1, 3, 1));
        table.addCell(createCell("银行账号", textfont, 1, 2, 1));
        table.addCell(createCell("", textfont, 1, 2, 1));

        table.addCell(createCell("类型", textfont, 1, 2, 1));
        table.addCell(createCell("自然人", textfont, 2, 2, 1, 0, 0, 0, 0));
        table.addCell(createCell("□", imageFont, 0, 1, 1, 0, 0, 0, 0));
        table.addCell(createCell("其他纳税人", textfont, 2, 2, 1, 0, 0, 0, 0));
        table.addCell(createCell("☑", imageFont, 0, 2, 1, 0, 1, 0, 0));


        table.addCell(createCell("减免税标识", textfont, 1, 2, 1));
        table.addCell(createCell("是", textfont, 2, 2, 1, 1, 0, 0, 0));
        table.addCell(createCell("□", imageFont, 0, 1, 1, 1, 0, 0, 0));
        table.addCell(createCell("否", textfont, 2, 2, 1, 1, 0, 0, 0));
        table.addCell(createCell("☑", imageFont, 0, 2, 1, 1, 1, 0, 0));


        table.addCell(createCell("受理税务机关", textfont, 1, 2, 8));
        table.addCell(createCell("税务机关税款征收岗位", textfont, 0, 7, 1, 1, 1, 0, 0));
        table.addCell(createCell("税收完税凭证号：", textfont, 0, 7, 1, 0, 1, 0, 0));
        table.addCell(createCell("", textfont, 1, 3, 1, 0, 0, 0, 0));
        table.addCell(createCell("（签字）", textfont, 0, 1, 1, 0, 0, 0, 0));
        table.addCell(createCell("    年   月  日", textfont, 1, 3, 1, 0, 1, 0, 0));

        table.addCell(createCell("税务机关代开发票岗位", textfont, 0, 7, 1, 1, 1, 0, 0));
        table.addCell(createCell("发票代码：", textfont, 0, 7, 1, 0, 1, 0, 0));
        table.addCell(createCell("发票号码：", textfont, 0, 7, 1, 0, 1, 0, 0));
        table.addCell(createCell("（签字）", textfont, 2, 7, 1, 0, 1, 0, 0));
        table.addCell(createCell("                  年        月       日  ", textfont, 0, 7, 1, 0, 1, 1, 0));

        table.addCell(createCell("经办人", textfont, 1, 2, 3));
        table.addCell(createCell("经核对，所开发票与申报单内容一致。", textfont, 0, 7, 1, 1, 1, 0, 0));
        table.addCell(createCell(" ", textfont, 0, 3, 1, 0, 0, 0, 0));
        table.addCell(createCell("经办人（签字）：", textfont, 0, 4, 1, 0, 1, 0, 0));
        table.addCell(createCell("                  年        月       日  ", textfont, 2, 7, 1, 0, 1, 1, 0));

        return table;
    }
    /**
     * 个人基本情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createGrjbqkTable(Document doc) throws DocumentException, IOException {
        // 添加图片
//        Image image = Image.getInstance("https://img2.baidu.com/it/u=1603121828,1164719810&fm=253&fmt=auto&app=138&f=JPEG?w=769&h=500");
//        Image image = Image.getInstance("D:\\test\\pic\\b2.jpg");
//        image.setAlignment(Image.ALIGN_CENTER);
//        image.scalePercent(40); //依照比例缩放
//        image.setAbsolutePosition(40, 60);

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("姓名", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("张三", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("性别", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("女", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("出生年月(年龄)", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("1991.02(32)", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("民族", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("汉族", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("籍贯（出生地）", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("陕西西乡", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("最高学历", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("本科", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("政治面貌", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("中共党员", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("参加组织时间", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2011.11", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("参加工作时间", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2014.01", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("婚姻状况", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("未婚", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("健康状态", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("健康", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("身份类别", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("公务员", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("所在单位及职务（职级）", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("XX市税务局办公室副主任", textfont, ALIGN_CENTER, 5, 1));
        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 个人履历情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createGrllTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("起始时间", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("截止时间", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("职务层次", keyfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2010.09", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2013.07", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("西安财经学院学生", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2013.07", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2015.08", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("西安塞特金属材料开发有限公司员工", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2015.08", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2016.08", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("XX县地方税务局未定职公务员", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2016.08", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2018.09", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("XX县地方税务局办公室科员", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2018.09", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2019.05", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("XX县税务局办公室科员", textfont, ALIGN_CENTER, 4, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 履职记录情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createLzjlTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("序号", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("岗位", keyfont, ALIGN_CENTER, 4, 1));
        table.addCell(createCell("得分", keyfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("1", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("信访岗", textfont, ALIGN_CENTER, 4, 1));
        table.addCell(createCell("87", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("2", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("公文处理岗", textfont, ALIGN_CENTER, 4, 1));
        table.addCell(createCell("67", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("3", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("新闻宣传岗", textfont, ALIGN_CENTER, 4, 1));
        table.addCell(createCell("99", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("4", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("考勤情况", textfont, ALIGN_CENTER, 4, 1));
        table.addCell(createCell("67", textfont, ALIGN_CENTER, 1, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 重点工作情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createZdgzTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("工作名称", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("工作层级", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("起止时间", keyfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("成品油专项工作", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("总局级", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2021.05-2022.05", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("成品油专项工作2", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("总局级2", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2022.05-2022.05", textfont, ALIGN_CENTER, 4, 1));

        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 学历学位情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createXlxwTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("教育类别", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("学历", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("专业类别", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("专业名称", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("学位", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("学校", keyfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("全日制教育", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("大学", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("经济学类", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("会计学", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("本科", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("中央财经大学", textfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("在职教育", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("研究生", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("经济学类", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("会计学", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("硕士", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("中央财经大学", textfont, ALIGN_CENTER, 1, 1));

        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 年度考核情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createNdkhTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("近三年及当年考核情况", keyfont, ALIGN_CENTER, 6, 1));

        table.addCell(createCell("年份", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("年度考核等次", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("考核划段情况", keyfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2020年", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("称职", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("第二段（非末位）", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2021年", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("称职", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("第二段（非末位）", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2022年", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("称职", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("第二段（非末位）", textfont, ALIGN_CENTER, 4, 1));

        table.addCell(createCell("2023年", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("一季度“较好”、二季度“较好”", textfont, ALIGN_CENTER, 5, 1));

        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 奖励惩戒情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createJlcjTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("奖励标志", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("奖励名称", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("奖励原因", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("批准机关", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("批准时间", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("所属年度", keyfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("奖励1", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("好人好事", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("干了一件好事情", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("陕西省税务机关", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2023-10-10", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2023", textfont, ALIGN_CENTER, 1, 1));


        table.addCell(createCell("奖励2", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("好人好事2", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("干了2件好事情", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("陕西省税务机关", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2023-10-10", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("2023", textfont, ALIGN_CENTER, 1, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 人才及两测情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createRcjlcTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("人才类型", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("人才级别", keyfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("专业类别", keyfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("入库时间", keyfont, ALIGN_CENTER, 1, 1));

        table.addCell(createCell("青年才俊", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("省局级", textfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("综合管理类", textfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("2022.05", textfont, ALIGN_CENTER, 1, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 性格行为情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createXgxwTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("人格类型", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("ISTJ（内向、实际、逻辑、计划性）", textfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("喜欢遵守规则，注重实际问题，善于逻辑分析，具有很强的计划性。", textfont, ALIGN_CENTER, 3, 1));

        table.addCell(createCell("行为风格", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("支配型", textfont, ALIGN_CENTER, 2, 1));
        table.addCell(createCell("通常目标明确，果断坚决，强调成果和目标的实现。他们喜欢控制局面，做决策迅速，并且喜欢追求挑战和竞争。", textfont, ALIGN_CENTER, 3, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    /**
     * 家庭成员情况
     *
     * @param doc
     * @return
     * @throws DocumentException
     * @throws IOException
     */
    public static PdfPTable createJtcyTable(Document doc) throws DocumentException, IOException {

        PdfPTable table = new PdfPTable(6);

        table.addCell(createCell("姓名", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("关系", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("出生年月", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("民族", keyfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("单位及职位", keyfont, ALIGN_CENTER, 2, 1));

        table.addCell(createCell("李春风", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("父亲", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("1955.04", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("汉族", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("陕西省汉中市中山街小学教师（已退休）", textfont, ALIGN_CENTER, 2, 1));

        table.addCell(createCell("李牧一", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("兄弟", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("1985.04", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("汉族", textfont, ALIGN_CENTER, 1, 1));
        table.addCell(createCell("陕西省汉中市中山街中学教师", textfont, ALIGN_CENTER, 2, 1));


        //设置table的宽度并且锁定
        table.setTotalWidth(PageSize.A4.getWidth() - 100);
        table.setLockedWidth(true);
        doc.add(table);
        return table;
    }

    public static PdfPTable createTable2(PdfWriter writer) throws DocumentException, IOException {
        // 添加图片
//        Image image = Image.getInstance("https://img2.baidu.com/it/u=1603121828,1164719810&fm=253&fmt=auto&app=138&f=JPEG?w=769&h=500");
//        Image image = Image.getInstance("D:\\test\\pic\\img3.png");
//        image.setAlignment(Image.ALIGN_CENTER);
//        image.scalePercent(40); //依照比例缩放
//        image.setAbsolutePosition(20,60);


        String rowList = "[{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":1233,\"qxsl\":1023,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":435,\"qxsl\":43,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"02\",\"qxzsl\":543,\"qxsl\":342,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":875,\"qxsl\":543,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":876,\"qxsl\":645,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":865,\"qxsl\":76,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":765,\"qxsl\":645,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":765,\"qxsl\":76,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":645,\"qxsl\":42,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":423,\"qxsl\":76,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":876,\"qxsl\":86,\"zbmc\":\"入库税额\"},{\"tjnd\":\"2023\",\"bhlb\":\"01\",\"qxzsl\":1233,\"qxsl\":2345,\"zbmc\":\"【2023】年全国【88.27%】的县区【纳税人数量】同比【增长】\"},{\"tjnd\":\"2022\",\"bhlb\":\"02\",\"qxzsl\":34543,\"qxsl\":5676,\"zbmc\":\"【2023】年全国【34.27%】的县区【纳税人数量】同比【减少】\"}]";
        String colList = "[{\"colend\":1,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"djxh\",\"colbegin\":1,\"rowbegin\":1,\"columncommnet\":\"序号\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"16%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4010,\"rowend\":1},{\"colend\":2,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"bhlb\",\"colbegin\":2,\"rowbegin\":1,\"columncommnet\":\"变化类别\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"16%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4011,\"rowend\":1},{\"colend\":3,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"qxsl\",\"colbegin\":3,\"rowbegin\":1,\"columncommnet\":\"区县数量\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"16%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4012,\"rowend\":1},{\"colend\":4,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"qxzsl\",\"colbegin\":4,\"rowbegin\":1,\"columncommnet\":\"区县总数量\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"16%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4013,\"rowend\":1},{\"colend\":5,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"zbmc\",\"colbegin\":5,\"rowbegin\":1,\"columncommnet\":\"指标名称\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"17%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4014,\"rowend\":1},{\"colend\":6,\"bbDm\":\"100302\",\"sort\":\"\",\"align\":\"center\",\"columnname\":\"tjnd\",\"colbegin\":6,\"rowbegin\":1,\"columncommnet\":\"统计年度\",\"autoincrement\":\"\",\"drilltype\":\"\",\"width\":\"17%\",\"drillurl\":\"\",\"fixed\":\"\",\"id\":4015,\"rowend\":1}]";
        List<Map<String, Object>> rows = JsonUtils.str2List(rowList);
        List<Map<String, Object>> cols = JsonUtils.str2List(colList);

        System.out.println("rows = " + rows);
        System.out.println("cols = " + cols);
        Map<Integer, String> titleMap = new HashMap<>();
        PdfPTable table = new PdfPTable(cols.size());
        for (int i = 0; i < cols.size(); i++) {
            titleMap.put(CastUtils.cast2Int(cols.get(i).get("colbegin")), CastUtils.cast2Str(cols.get(i).get("columnname")));
            table.addCell(createCell(CastUtils.cast2Str(cols.get(i).get("columncommnet")), textfont, 1, 1, 1));
        }
        System.out.println("titleMap = " + titleMap);
        for (int i = 0; i < rows.size(); i++) {
            Map<String, Object> rowMap = rows.get(i);
            for (int j = 0, col = 1; j < cols.size(); j++, col++) {
                System.out.println("col = " + col);
                String text = CastUtils.cast2Str(rowMap.get(titleMap.get(col)));
                System.out.println("text = " + text);
                table.addCell(createCell(text, textfont, 1, 1, 1));
            }


        }

//        table.addCell(createCell("个人信息",textfont,1,1,3));
//        table.addCell(createCell("名称",textfont,1,1));
//        table.addCell(createCell("",textfont,1,3,1));
//        table.addCell(createCell("照片",textfont,1,2,3));
//
//        table.addCell(createCell(image,textfont,1,2,3));
//
//        table.addCell(createCell("地址",textfont,1,1));
//        table.addCell(createCell("",textfont,1,3,1));
//
//        table.addCell(createCell("电话",textfont,1,1));
//        table.addCell(createCell("",textfont,1,3,1));


        return table;
    }


    /**
     * ------------------------创建表格单元格的方法start----------------------------
     */
    public static PdfPCell createCell(Image image, Font font, int align, int colspan, int rowspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setFixedHeight(rowspan * 25f);
        cell.setImage(image);
        // cell.setPhrase(new Phrase(new Chunk(image, 0, 0,false)));
        return cell;
    }

    public static PdfPCell createCell(Image image, Font font, int align, int colspan, int rowspan, int borderWidthTop, int borderWidthRight, int borderWidthBottom, int borderWidthLeft) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setFixedHeight(rowspan * 25f);
        cell.setImage(image);
        //去除边框
        cell.setBorderWidthTop(borderWidthTop);
        cell.setBorderWidthRight(borderWidthRight);
        cell.setBorderWidthBottom(borderWidthBottom);
        cell.setBorderWidthLeft(borderWidthLeft);
        return cell;
    }

    /**
     * 创建单元格(指定字体)
     *
     * @param value
     * @param font
     * @return
     */
    public static PdfPCell createCell(String value, Font font) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPhrase(new Phrase(value, font));
        cell.setFixedHeight(25f);
        return cell;
    }

    /**
     * 创建单元格（指定字体、水平..）
     *
     * @param value
     * @param font
     * @param align
     * @return
     */
    public static PdfPCell createCell(String value, Font font, int align) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        cell.setFixedHeight(25f);
        return cell;
    }

    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并）
     *
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @return
     */
    public static PdfPCell createCell(String value, Font font, int align, int colspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }

    public static PdfPCell createCell(String value, Font font, int align, int colspan, int rowspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setFixedHeight(rowspan * 25f);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }

    public static PdfPCell createCell(String value, Font font, int align, int colspan, int rowspan, int borderWidthTop, int borderWidthRight, int borderWidthBottom, int borderWidthLeft) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setRowspan(rowspan);
        cell.setFixedHeight(rowspan * 25f);
        cell.setPhrase(new Phrase(value, font));
        //去除边框
        cell.setBorderWidthTop(borderWidthTop);
        cell.setBorderWidthRight(borderWidthRight);
        cell.setBorderWidthBottom(borderWidthBottom);
        cell.setBorderWidthLeft(borderWidthLeft);
        return cell;
    }

    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并、设置单元格内边距）
     *
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @param boderFlag
     * @return
     */
    public static PdfPCell createCell(String value, Font font, int align, int colspan, boolean boderFlag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        cell.setPadding(3.0f);
        if (!boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(15.0f);
            cell.setPaddingBottom(8.0f);
        } else if (boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(0.0f);
            cell.setPaddingBottom(15.0f);
        }
        return cell;
    }

    /**
     * 创建单元格（指定字体、水平..、边框宽度：0表示无边框、内边距）
     *
     * @param value
     * @param font
     * @param align
     * @param borderWidth
     * @param paddingSize
     * @param flag
     * @return
     */
    public static PdfPCell createCell(String value, Font font, int align, float[] borderWidth, float[] paddingSize, boolean flag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setFixedHeight(25f);
        cell.setPhrase(new Phrase(value, font));
        cell.setBorderWidthLeft(borderWidth[0]);
        cell.setBorderWidthRight(borderWidth[1]);
        cell.setBorderWidthTop(borderWidth[2]);
        cell.setBorderWidthBottom(borderWidth[3]);
        cell.setPaddingTop(paddingSize[0]);
        cell.setPaddingBottom(paddingSize[1]);
        if (flag) {
            cell.setColspan(2);
        }
        return cell;
    }
/**------------------------创建表格单元格的方法end----------------------------*/


/**--------------------------创建表格的方法start------------------- ---------*/


    /**
     * 创建默认列宽，指定列数、水平(居中、右、左)的表格
     *
     * @param colNumber
     * @param align
     * @return
     */
    public static PdfPTable createTable(int colNumber, int align) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(align);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }

    /**
     * 创建指定列宽、列数的表格
     *
     * @param widths
     * @return
     */
    public static PdfPTable createTable(float[] widths) {
        PdfPTable table = new PdfPTable(widths);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }

    /**
     * 创建空白的表格
     *
     * @return
     */
    public static PdfPTable createBlankTable() {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorder(0);
        table.addCell(createCell("", keyfont));
        table.setSpacingAfter(20.0f);
        table.setSpacingBefore(20.0f);
        return table;
    }
/**--------------------------创建表格的方法end------------------- ---------*/
}
